<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxSlideshow;
use App\Models\WxAttachment;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxSlideshowController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxSlideshow(), function (Grid $grid) {
//            $grid->column('id')->sortable();
            $grid->column('poster')->image('',80);
            $grid->column('sort')->editable();
            $grid->column('slideshow_type')->using([0 => '链接',1 => '帖子', 2 => '圈子',])->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default

            ]);

            $grid->column('slideshow_state')->switch();
//            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxSlideshow(), function (Show $show) {
            $show->field('id');
            $show->field('poster');
            $show->field('link');
            $show->field('posts_id');
            $show->field('circle_id');
            $show->field('slideshow_type');
            $show->field('slideshow_state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxSlideshow(), function (Form $form) {
            $form->display('id');
            $form->image('poster')->help('建议尺寸公众号首图尺寸：900*383')
                ->url('files/uploads');
            $form->number('sort');
            $form->radio('slideshow_type')
                ->when(0, function (Form $form) {
                    // 值为1和4时显示文本框
                    $form->text('link');
                })
                ->when(1, function (Form $form) {
                    $form->text('posts_id');
                })
                ->when(2, function (Form $form) {
                    $form->text('circle_id');
                })
                ->options([
                    0 => '链接',
                    1 => '帖子',
                    2 => '圈子',

                ])
                ->default(0);



//            $form->text('slideshow_type');


            $form->switch('slideshow_state');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
